class Solution {
public:
    vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {
        int n = spells.size(), m = potions.size();
        vector<int> ret(n);

        sort(potions.begin(), potions.end());

        for (int i = 0; i < n; i++) {
            long long a = spells[i];
            if (a * potions[m - 1] < success) {
                ret[i] = 0;
                continue;
            }
            int left = 0, right = m - 1;
            while (left < right) {
                int mid = (left + right) / 2;
                long long b = potions[mid];
                if (a * b >= success) right = mid;
                else left = mid + 1;
            }
            ret[i] = m - 1 - right + 1;
        }
        return ret;
    }
};